﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PokeData;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Media;

namespace PokeTD
{
    public enum Typ { Normal, Feuer, Wasser, Pflanze, Elektro, Eis, Kampf, Gift, Boden, Flug, Psycho, Käfer, Gestein, Geist, Drache, Unlicht, Stahl };
    public enum Direction { Left, Right, Up, Down };
    public enum DashboardState { BuyTower, UpgradeTower, none };

    class Globals
    {
        public static ParticleSystem ParticleSystem;
        public static MessageSystem MessageSystem;
        public static ContentManager Content;

        public static double[][] dmgtbl = new double[][] 
        {
            new double[] {1,1,1,1,1,1,1,1,1,1,1,1,0.5,0,1,1,0.5}, //Normal
            new double[] {1,0.5,0.5,2,1,2,1,1,1,1,1,2,0.5,1,0.5,1,2}, //Feuer
            new double[] {1,2,0.5,0.5,1,1,1,1,2,1,1,1,2,1,0.5,1,1}, // Wasser
            new double[] {1,0.5,2,0.5,1,1,1,0.5,2,0.5,1,0.5,2,1,0.5,1,0.5}, //Pflanze
            new double[] {1,1,2,0.5,0.5,1,1,1,0,2,1,1,1,1,2,1,0.5}, //Elektro
            new double[] {1,0.5,0.5,2,1,0.5,1,1,2,2,1,1,1,1,2,1,0.5}, //Eis
            new double[] {2,1,1,1,1,2,1,0.5,1,0.5,0.5,0.5,1,0,1,2,2}, //Kampf
            new double[] {1,1,1,2,1,1,1,0.5,0.5,1,1,1,0.5,0.5,1,1,0}, //Gift
            new double[] {1,2,1,0.5,2,1,1,2,1,0,1,0.5,2,1,1,1,2}, //Boden
            new double[] {1,1,1,2,0.5,1,2,1,1,1,1,2,0.5,1,1,1,0.5}, //Flug
            new double[] {1,1,1,1,1,1,2,2,1,1,0.5,1,1,1,1,0,0.5}, //Psycho
            new double[] {1,0.5,1,2,1,1,0.5,0.5,1,0.5,2,1,1,0.5,1,2,0.5}, // Käfer
            new double[] {1,2,1,1,1,2,0.5,1,0.5,2,1,2,1,1,1,1,0.5}, // Gestein
            new double[] {0,1,1,1,1,1,1,1,1,1,2,1,1,2,1,0.5,0.5}, // Geist
            new double[] {1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,0.5}, //Drache
            new double[] {1,1,1,1,1,1,0.5,1,1,1,2,1,1,2,1,0.5,0.5}, //Unlicht
            new double[] {1,0.5,0.5,1,0.5,2,1,1,1,1,1,1,2,1,1,1,0.5} //Stahl
        };
        public static bool GamePaused = false;
        public static WavesDS waveDS;
        public static TilesetDS tilesetDS;
        public static bool mediaPlaying = false;

        /// <summary>
        /// Überprüft die Effektivität von Einfachtypen
        /// </summary>
        /// <param name="typ1">Typ des Angreifers</param>
        /// <param name="typ2">Typ des Verteidigers</param>
        /// <returns>Damage Multiplier (0, 0.5, 1 oder 2)</returns>
        static public double checkEff(Typ typ1, Typ typ2)
        {
            if (((int)typ2 == -1) || ((int)typ2 == -1))
                return 1;
            return dmgtbl[(int)typ1][(int)typ2];
        }

        /// <summary>
        /// Überprüft die Effektivität von Einfachtypen
        /// </summary>
        /// <param name="typ1">Typ des Angreifers</param>
        /// <param name="typ2a">Typ 1 des Verteidigers</param>
        /// <param name="typ2b">Typ 2 des Verteidigers</param>
        /// <returns>Damage Multiplier</returns>
        static public double checkEff(Typ typ1, Typ typ2a, Typ typ2b)
        {
            double dmg1 = checkEff(typ1, typ2a);
            double dmg2 = checkEff(typ1, typ2b);
            return dmg1 * dmg2;
        }
    }

    public class MultiValueDictionary<TKey, TValue> : Dictionary<TKey, List<TValue>>
    {

        public void Add(TKey key, TValue value)
        {
            if (!ContainsKey(key))
                Add(key, new List<TValue>());
            this[key].Add(value);
        }

        public List<TValue> GetValues(TKey key)
        {
            return this[key];
        }

        public List<TValue> GetAllValues()
        {
            List<TValue> list = new List<TValue>();

            foreach (TKey key in this.Keys)
            {
                List<TValue> values = this.GetValues(key);
                list.AddRange(values);
            }

            return list;
        }
    }
}
